home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PASCTXT.ZIP / CHAP5.TXT < prev    next >
Text File  |  1988-01-15  |  28KB  |  653 lines

  1.  
  2.              CHAPTER 5 - The Pascal procedures and functions
  3.  
  4.  
  5.              In order to properly define procedures and functions we
  6.         need   to  lay  some  groundwork  in  the  form  of  a   few
  7.         definitions.   These  are important concepts, so  pay  close
  8.         attention.
  9.  
  10.         Program  Heading - This is the easiest part since it is only
  11.                   one  line,  at  least it has been in  all  of  our
  12.                   programs  up  to  this point.  It  is  simply  the
  13.                   "program" line, and it never needs to be any  more
  14.                   involved  than  it has been up to  this  point  in
  15.                   TURBO Pascal.
  16.  
  17.         Declaration  Part  - This is the part of the  Pascal  source
  18.                   code  in which all constants, variables, and  user
  19.                   defined  auxiliary  operations  are  defined.   In
  20.                   some of the programs we have examined, there  have
  21.                   been one or more var declarations.  These are  the
  22.                   only  components of the declaration part  we  have
  23.                   used  to  this  point.  There  are  actually  five
  24.                   components  in  the  declaration  part,  and   the
  25.                   procedures  and functions are the fifth part.   We
  26.                   will cover the others in the next chapter.
  27.  
  28.         Statement Part  -  This  is  the last  part  of  any  Pascal
  29.                   program,  and it is what we have been calling  the
  30.                   main  program.   It  is  one  compound   statement
  31.                   bracketed  with  the reserved  words  "begin"  and
  32.                   "end".
  33.  
  34.              It   is  very  important  that  you  grasp  the   above
  35.         definitions because we will be referring to them  constantly
  36.         during  this chapter, and throughout the remainder  of  this
  37.         tutorial.   With that introduction, lets go on to our  first
  38.         Pascal program with a procedure in it, in fact, it will have
  39.         three procedures.
  40.  
  41.                            THE FIRST PROCEDURES
  42.  
  43.              Load  PROCED1  as  your  first  example  file  with   a
  44.         procedure  and display it on your monitor.  You will  notice
  45.         that it doesn't look like anything you have seen up to  this
  46.         point because it has procedures in it.  Lets go back to  our
  47.         definitions  from  above.   The first line  is  the  Program
  48.         Heading  which should pose no difficulty.   The  Declaration
  49.         Part  begins with the var statement in line 4 and  continues
  50.         down  through and including all three procedures  ending  in
  51.         line 19.  Lines 21 through 26 constitute the Statement Part.
  52.         It  may  seem  strange that what appears  to  be  executable
  53.         Pascal   statements,   and  indeed   they   are   executable
  54.         statements,  are  contained in the Declaration  Part  rather
  55.         than  the  Statement Part.  This is because  of  the  Pascal
  56.  
  57.  
  58.                                  Page 26
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.              CHAPTER 5 - The Pascal procedures and functions
  69.  
  70.  
  71.         definition and it will make sense when we have completed our
  72.         study of procedures and functions.
  73.  
  74.              Continuing to examine PROCED1, we will make note of the
  75.         program  itself, which is the Statement Part.  The  program,
  76.         due  to  the  nature  of Pascal  and  the  carefully  chosen
  77.         procedure names, clearly tells us what it will do.  It  will
  78.         write  a  header, eight messages, and an ending.   The  only
  79.         problem  we  are  faced with is, how  will  it  write  these
  80.         messages?  This is where the Declaration Part is called upon
  81.         to define these operations in detail.  The Declaration  Part
  82.         contains  the three procedures which will completely  define
  83.         what  is  to  be done by the procedure  calls  in  the  main
  84.         program.
  85.  
  86.              It  should be clear to you that the definitions of  the
  87.         procedures  should be in the Definition Part of the  program
  88.         because  that  is exactly what they do.  In the  case  of  a
  89.         var,  a  variable  is  defined for later  use  by  the  main
  90.         program,  and  in  the case of a  procedure,  the  procedure
  91.         itself is defined for later use by the main program.
  92.  
  93.              Lets arbitrarily pick one of the procedures, the first,
  94.         and examine it in detail.  The first executable statement we
  95.         come  to  in the main program is line 22  and  says  simply,
  96.         Write_A_Header, followed by the usual end of statement,  the
  97.         semicolon.   This  is  a simple procedure  call.   When  the
  98.         compiler  finds  this  statement  it  goes  looking  for   a
  99.         predefined procedure of that name which it can execute.   If
  100.         it finds one in the Declaration Part of the program, it will
  101.         execute  that procedure.  If it doesn't find a user  defined
  102.         procedure,  it will search the Pascal library for  a  system
  103.         defined  procedure  and execute it.  The Write  and  Writeln
  104.         statements are system procedures, and you have already  been
  105.         using them quite a bit, so procedures are not completely new
  106.         to you.  If it doesn't find the procedure defined in  either
  107.         place, it will generate an error message.
  108.  
  109.                           HOW TO CALL A PROCEDURE
  110.  
  111.              To call a procedure, we simply need to state its  name.
  112.         To  define  a  simple procedure, we use  the  reserved  word
  113.         "procedure"  followed by its calling name, with a  semicolon
  114.         as a terminator.  Following the Procedure Heading, there  is
  115.         the  Declaration  Part of the procedure followed by  a  body
  116.         which is nothing more than a compound statement bracketed by
  117.         the reserved words "begin" and "end".  This is identical  to
  118.         the  Statement  Part  of the main program  except  that  the
  119.         procedure  ends with a semicolon instead of a  period.   Any
  120.         valid  Pascal  statements can be put between the  begin  and
  121.  
  122.  
  123.  
  124.                                  Page 27
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.              CHAPTER 5 - The Pascal procedures and functions
  135.  
  136.  
  137.         end, and in fact, there is no difference in what can be  put
  138.         in a procedure and what can be put in the main program.
  139.  
  140.              The  program we are examining would be no different  if
  141.         we  would eliminate the first procedure completely and  move
  142.         the  Writeln contained in it down to the Statement  Part  in
  143.         place of Write_A_Header.  If that is not clear, go back  and
  144.         reread the last two paragraphs until it is.
  145.  
  146.              Lines  23  and  24  will  cause  the  procedure   named
  147.         Write_A_Message  to be called 8 times, each time  writing  a
  148.         line  of  output.  Suffice it to say at this time  that  the
  149.         value  of the variable Count, as defined here, is  available
  150.         globally, meaning anywhere in the entire Pascal program.  We
  151.         will  define the scope of variables shortly.   Finally,  the
  152.         last  procedure call is made, causing the ending message  to
  153.         be displayed, and the program execution is complete.
  154.  
  155.              Having examined your first Pascal procedures, there  is
  156.         a fine point that is obvious but could be easily overlooked.
  157.         We  mentioned  the  unbroken rule of Pascal  in  an  earlier
  158.         chapter  and it must be followed here too.  "Nothing can  be
  159.         used  in Pascal until it has been defined".  The  procedures
  160.         must  all be defined ahead of any calls to them, once  again
  161.         emphasizing  the fact that they are part of the  Declaration
  162.         Part of the program, not the Statement Part.
  163.  
  164.              Compile and run PROCED1 to verify that it does what you
  165.         expect it to do.
  166.  
  167.                            MORE PROCEDURE CALLS
  168.  
  169.              Assuming   you  have  run  PROCED1   successfully   and
  170.         understand its output, lets go on to PROCED2 and examine it.
  171.         In this program we will see how to call a procedure and take
  172.         along  some  data for use within the  procedure.   To  begin
  173.         with,  notice  that there are three procedure calls  in  the
  174.         Statement  Part  of the program and each has  an  additional
  175.         term not contained in the calls in the last program,  namely
  176.         the  variable name Index within brackets.  This  is  Pascals
  177.         way of taking a variable parameter to the procedure when  it
  178.         is called.
  179.  
  180.              You  will notice that the variable Index is defined  as
  181.         an integer variable in the very top of the Declaration Part.
  182.         Since  we are taking an integer type variable along when  we
  183.         visit  the  procedure  Print_Data_Out,  it  had  better   be
  184.         expecting  an  integer variable as input or we will  have  a
  185.         type  mismatch.   In fact, observing the  procedure  heading
  186.         itself  in line 7, indicates that it is indeed expecting  an
  187.         integer  variable but it prefers to call the variable  Puppy
  188.  
  189.  
  190.                                  Page 28
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.              CHAPTER 5 - The Pascal procedures and functions
  201.  
  202.  
  203.         inside  of  the procedure.  Calling it  something  different
  204.         poses no problem as long as the main program doesn't try  to
  205.         call  its variable Puppy, and the procedure doesn't  try  to
  206.         use the name Index.  Both are actually referring to the same
  207.         piece  of  data  but  they simply wish to  refer  to  it  by
  208.         different names.
  209.  
  210.              Observe that the next procedure is called with Index as
  211.         a parameter and the procedure prefers to call it by the name
  212.         Cat.   In  both cases, the procedures simply print  out  the
  213.         parameter  passed  to it, and each then try  to  modify  the
  214.         value passed to it before passing it back.  We will see that
  215.         one will be successful and the other will not.
  216.  
  217.              We  are in a loop in which Count is incremented from  1
  218.         to  3  and  Pascal  does not allow us  to  modify  the  loop
  219.         variable so we make a copy of the value in line 21 and  call
  220.         it  Index.  We can then modify Index in the main program  if
  221.         we desire.
  222.  
  223.                                CALL BY VALUE
  224.  
  225.              In line 7, the procedure heading does not contain a var
  226.         in front of the passed parameter and therefore the parameter
  227.         passing  is  only  one  way because of  the  way  Pascal  is
  228.         defined.   Without  the reserved word var in  front  of  the
  229.         variable Puppy, the system makes a copy of Index, and passes
  230.         the  copy  to the procedure which can do anything  with  it,
  231.         using  its new name, Puppy, but when control returns to  the
  232.         main  program, the original value of Index is  still  there.
  233.         The copy of Index named Puppy is modified in the  procedure,
  234.         but  the original variable Index remains unchanged.  So  you
  235.         can think of the passed parameter without the var as one way
  236.         parameter  passing.  This is a "call by value" because  only
  237.         the value of the variable is passed to the procedure.
  238.  
  239.                              CALL BY REFERENCE
  240.  
  241.              In line 13, the second procedure has the reserved  word
  242.         "var" in front of its desired name for the variable,  namely
  243.         Cat, so it can not only receive the variable, it can  modify
  244.         it,  and return the modified value to the main  program.   A
  245.         copy  is not made, but the original variable named Index  is
  246.         actually  passed  to this procedure and  the  procedure  can
  247.         modify  it, therefore communicating with the  main  program.
  248.         The  name Catin the procedure is actually another  name  for
  249.         the  variable  named Index in the main  program.   A  passed
  250.         parameter  with a var in front of it is therefore a two  way
  251.         situation.   This  is  a  "call  by  reference"  since   the
  252.         reference  to  the  original  variable  is  passed  to   the
  253.         procedure.
  254.  
  255.  
  256.                                  Page 29
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.              CHAPTER 5 - The Pascal procedures and functions
  267.  
  268.  
  269.  
  270.                             SOME NEW TERMINOLOGY
  271.  
  272.              The  parameter name in the calling program is  referred
  273.         to  as the actual parameter, and the parameter name  in  the
  274.         procedure  is referred to as the formal parameter.   In  the
  275.         last  example then, the actual parameter is named Index  and
  276.         the  formal  parameter in the procedure is  named  Cat.   It
  277.         should  be pointed out that it is called a formal  parameter
  278.         whether  it is a "call by reference" or a "call  by  value".
  279.         This   terminology  is  used  in  many   other   programming
  280.         languages, not only in Pascal.
  281.  
  282.              When you run this program, you will find that the first
  283.         procedure  is unable to return the value of 12 back  to  the
  284.         main program, but the second procedure does in fact  succeed
  285.         in returning its value of 35 to the main program.  Spend  as
  286.         much time as you like studying this program until you  fully
  287.         understand  it.  It should be noted that as many  parameters
  288.         as  desired can be passed to and from a procedure by  simply
  289.         making  a  list  separated  by  commas  in  the  calls,  and
  290.         separated  by  semicolons in the procedure.   This  will  be
  291.         illustrated in the next example program.
  292.  
  293.              Compile  and  run PROCED2 and study  the  output.   You
  294.         should  be able to comprehend all of the output.  If  it  is
  295.         not clear, reread the last few paragraphs.
  296.  
  297.              For  your  own enlightenment, examine  PROCED3  for  an
  298.         example  of a procedure call with more than one variable  in
  299.         the call.  Normally, you would group the three input  values
  300.         together to make the program more readable, but for purposes
  301.         of  illustration,  they  are separated.   Observe  that  the
  302.         variable  Fruit is a two way variable because it is the  3rd
  303.         variable in the actual parameter list and corresponds to the
  304.         3rd formal parameter in the procedure header.
  305.  
  306.              Compile  and run PROCED3 to see that it does  what  you
  307.         expect it to do based on the above explanation.
  308.  
  309.                   "CALL BY REFERENCE" OR "CALL BY VALUE"?
  310.  
  311.              It  may  seem to you that it would be a  good  idea  to
  312.         simply  put the word var in front of every formal  parameter
  313.         in  every procedure header to gain maximum flexibility,  but
  314.         using  all  "call by references" could actually  limit  your
  315.         flexibility.   There are two reasons to use "call by  value"
  316.         variables when you can.  First is simply to shield some data
  317.         from  being corrupted by the procedure.  This is becoming  a
  318.         very  important  topic  is  Software  Engineering  known  as
  319.         "information hiding" and is the primary basis behind  Object
  320.  
  321.  
  322.                                  Page 30
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.              CHAPTER 5 - The Pascal procedures and functions
  333.  
  334.  
  335.         Oriented  Programming which is far beyond the scope of  this
  336.         tutorial.
  337.  
  338.              Secondly  is  the  ability to use  a  constant  in  the
  339.         procedure call.  Modify line 17 of PROCED3 as follows;
  340.  
  341.            Add_The_Fruit(12,Orange,Fruit,Pear);
  342.  
  343.         and compile and run the program.  Since Value1 is a "call by
  344.         value",  the  constant 12 can be used and the  program  will
  345.         compile and run.  However, if you change line 17 to;
  346.  
  347.            Add_The_Fruit(Apple,Orange,32,Pear);
  348.  
  349.         you  will find that it will not compile because Total  is  a
  350.         "call by reference" and the system must be able to return  a
  351.         value  for  the formal parameter Total.  It cannot  do  this
  352.         because 32 is a constant, not a variable.
  353.  
  354.              The  prior discussion should indicate to you that  both
  355.         "call by value" and "call by reference" have a useful  place
  356.         in  Pascal programming and it is up to you to  decide  which
  357.         you should use.
  358.  
  359.              When  you are satisfied with the present  illustration,
  360.         we will go on to study the scope of variables using PROCED4.
  361.  
  362.                         A MULTIPLY DEFINED VARIABLE
  363.  
  364.              If  you will examine PROCED4, you will notice that  the
  365.         variable  Count is defined twice, once in the  main  program
  366.         var  block  and once in the var block contained  within  the
  367.         procedure  named Print_Some_Data.  This is  perfectly  legal
  368.         and is within the Pascal definition.
  369.  
  370.              The variable Index is defined only in the main  program
  371.         var  block  and is valid anywhere within the  entire  Pascal
  372.         program,  including the procedures.  The variable  Count  is
  373.         also  defined  in the main program var block  and  is  valid
  374.         anywhere within the entire Pascal program, except within the
  375.         procedure  where another variable is defined with  the  same
  376.         name  Count.   The two variables with the same name  are  in
  377.         fact,   two  completely  different  variables,   one   being
  378.         available only outside of the procedure and the other  being
  379.         available   only   within  the  procedure.    The   variable
  380.         More_Stuff  is  defined  within  the  procedure,  so  it  is
  381.         invisible  to  the main program, since it is  defined  at  a
  382.         lower level than that of the main program.
  383.  
  384.              Any  variable is available at any point in the  program
  385.         following its definition but only at the level of definition
  386.  
  387.  
  388.                                  Page 31
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.              CHAPTER 5 - The Pascal procedures and functions
  399.  
  400.  
  401.         or below.  This means that any procedure in the  Declaration
  402.         Part  of  a  program can use any  variable  defined  in  the
  403.         Declaration Part of the program provided that the definition
  404.         occurs  prior to the procedure.  Any variable defined  in  a
  405.         procedure  cannot  be  used by the main  program  since  the
  406.         definition is at a lower level than the main program.
  407.  
  408.              Be sure to compile and run PROCED4 before continuing on
  409.         to the next example program.
  410.  
  411.                     PROCEDURES CALLING OTHER PROCEDURES
  412.  
  413.              Load   and  examine  PROCED5  to  see  an  example   of
  414.         procedures  that call other procedures.  Keep in mind  that,
  415.         "Nothing can be used in Pascal until it has been  previously
  416.         defined", and the order of procedures will be clear in  this
  417.         example.   Note  that procedure Three  calls  procedure  Two
  418.         which in turn calls procedure One.
  419.  
  420.              Compile and run PROCED5 and study the output until  you
  421.         understand  why  it outputs each line in the order  that  it
  422.         does.
  423.  
  424.              Now   that  you  have  a  good  working  knowledge   of
  425.         procedures,  we  need  to  make  another  important   point.
  426.         Remember that any Pascal program is made up of three  parts,
  427.         the Program Heading, the Declaration Part, and the Statement
  428.         Part.   The  Declaration  Part is composed  of  five  unique
  429.         components,  four of which we will discuss in detail in  the
  430.         next  chapter, and the last component, which is composed  of
  431.         some  number  of procedures and functions.   We  will  cover
  432.         functions in the next example, so for now simply accept  the
  433.         fact  that  it  is like a procedure.  A  procedure  is  also
  434.         composed of three parts, a Procedure Heading, a  Declaration
  435.         Part, and a Statement Part.  A procedure, by definition,  is
  436.         therefore nothing more or less than another complete  Pascal
  437.         program embedded within the main program, and any number  of
  438.         procedures  can  be located in the Declaration Part  of  the
  439.         main program.  These procedures are all in a line, one right
  440.         after another.
  441.  
  442.              Since a procedure is defined like the main program,  it
  443.         would seem to be possible to embed another procedure  within
  444.         the  Declaration Part of any procedure.  This  is  perfectly
  445.         valid  and  is often done, but remember  that  the  embedded
  446.         procedure can only be called by the procedure in which it is
  447.         embedded,  not  by  the main program.  This  is  a  form  of
  448.         information  hiding  which  is becoming  popular  in  modern
  449.         software engineering.
  450.  
  451.  
  452.  
  453.  
  454.                                  Page 32
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.              CHAPTER 5 - The Pascal procedures and functions
  465.  
  466.  
  467.              The  previous paragraph is probably a bit difficult  to
  468.         grasp.   Don't  worry about it too much now, as  you  become
  469.         proficient as a Pascal programmer, you will very clearly see
  470.         how that is used.
  471.  
  472.                        NOW LET'S LOOK AT A FUNCTION
  473.  
  474.              Now  to keep a promise, lets examine the program  named
  475.         FUNCTION  to see what a function is and how to use  it.   In
  476.         this  very  simple program, we have a function  that  simply
  477.         multiplies  the  sum of two variables by 4 and  returns  the
  478.         result.   The  major  difference between a  function  and  a
  479.         procedure is that the function returns a single value and is
  480.         called  from  within a mathematical  expression,  a  Writeln
  481.         command,  or  anywhere that it is valid to use  a  variable,
  482.         since  it  is  really  a  variable  itself.   Observing  the
  483.         Function Heading of the function, in line 6, reveals the two
  484.         input variables inside the parenthesis pair being defined as
  485.         integer variables, and following the parenthesis is a  colon
  486.         and another "integer".  The last "integer" is used to define
  487.         the type of the variable being returned to the main program.
  488.  
  489.              Any  call to this function is actually replaced  by  an
  490.         integer upon completion of the call.  Therefore in line  14,
  491.         the function is evaluated and the value returned is used  in
  492.         place  of the function call.  The result of the function  is
  493.         assigned to the variable Feet.
  494.  
  495.              Note that a function always returns a value and it  may
  496.         return  additional  values  if some of  its  parameters  are
  497.         defined as "call by reference".  Be sure to compile and  run
  498.         this program.
  499.  
  500.                      NOW FOR THE MYSTERY OF RECURSION
  501.  
  502.              One of the great mysteries of Pascal to many people, is
  503.         the recursion of procedure calls.  Simply defined, recursion
  504.         is  the ability of a procedure to call itself.  Examine  the
  505.         Pascal  example file RECURSON for an example  of  recursion.
  506.         The main program is very simple, it sets the variable  Count
  507.         to the value 7 and calls the procedure  Print_And_Decrement.
  508.         The  procedure prefers to refer to the variable by the  name
  509.         Index but that poses no problem for us because we understand
  510.         that  the  name  of the formal parameter can  be  any  legal
  511.         identifier.   The  procedure  writes a  line  to  the  video
  512.         display with the value of Index written within the line, and
  513.         decrements the variable.
  514.  
  515.              The  if  statement introduces the interesting  part  of
  516.         this program.  If the variable is greater than zero, and  it
  517.         is  now 6, then the procedure Print_And_Decrement is  called
  518.  
  519.  
  520.                                  Page 33
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.              CHAPTER 5 - The Pascal procedures and functions
  531.  
  532.  
  533.         once again.  This might seem to create a problem except  for
  534.         the  fact  that  this is perfectly legal  in  Pascal.   Upon
  535.         entering  the procedure the second time, the value of  Index
  536.         is printed as 6, and it is once again decremented.  Since it
  537.         is  now 5, the same procedure will be called again,  and  it
  538.         will  continue until the value of Index is reduced  to  zero
  539.         when each procedure call will be completed one at a time and
  540.         control will return to the main program.
  541.  
  542.                         ABOUT RECURSIVE PROCEDURES
  543.  
  544.              This   is  really  a  stupid  way  to  implement   this
  545.         particular program, but it is the simplest recursive program
  546.         that can be written and therefore the easiest to understand.
  547.         You  will have occasional use for recursive  procedures,  so
  548.         don't  be afraid to try them.  Remember that  the  recursive
  549.         procedure  must have some variable converging to  something,
  550.         or you will have an infinite loop.
  551.  
  552.              Compile  and  run this program and  observe  the  value
  553.         decrementing as the recursion takes place.
  554.  
  555.                            THE FORWARD REFERENCE
  556.  
  557.              Occasionally  you  will  have a need  to  refer  to   a
  558.         procedure  before you can define it.  In that case you  will
  559.         need  a  forward  reference.  The  program  FORWARD  has  an
  560.         example of a forward reference in it.  In this program, each
  561.         one of the procedures calls the other, a form of  recursion.
  562.         This  program, like the last, is a very stupid way to  count
  563.         from  7 to 0, but it is the simplest program  possible  with
  564.         the forward reference.
  565.  
  566.              The  first  procedure,  Write_A_Line,  has  its  header
  567.         defined  in exactly the same manner as any  other  procedure
  568.         but instead of the normal procedure body, only the  reserved
  569.         word  "forward" is given.  This tells the compiler that  the
  570.         procedure  will  be defined later.  The  next  procedure  is
  571.         defined  as  usual, then the body of Write_A_Line  is  given
  572.         with  only the reserved word "procedure" and  the  procedure
  573.         name.  The variable reference has been defined earlier.   In
  574.         this  way,  each of the procedure names are  defined  before
  575.         they are called.
  576.  
  577.              It would be possible, by using the forward reference in
  578.         great  numbers,  to  move  the main  program  ahead  of  all
  579.         procedure  definitions and have the program structured  like
  580.         some  other languages.  This style of programming  would  be
  581.         perfectly legal as far as the compiler is concerned, but the
  582.         resulting  program would be very nonstandard and  confusing.
  583.         You  would  do  well  to  stick  with  conventional   Pascal
  584.  
  585.  
  586.                                  Page 34
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.              CHAPTER 5 - The Pascal procedures and functions
  597.  
  598.  
  599.         formatting   techniques  and  use  the   forward   reference
  600.         sparingly.
  601.  
  602.              Be sure you compile and run this program.
  603.  
  604.                            PROGRAMMING EXERCISES
  605.  
  606.         1.  Write a program to write your name,  address,  and phone
  607.             number with each Writeln in a different procedure.
  608.  
  609.         2.  Add a statement to the procedure in RECURSON to  display
  610.             the value of "Index" after the call to itself so you can
  611.             see  the  value increasing as the  recurring  calls  are
  612.             returned to the next higher level.
  613.  
  614.         3.  Rewrite  TEMPCONV putting the  centigrade to  fahrenheit
  615.             formulas in a function call.
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.                                  Page 35
  653.